package com.example.ymm.modules1.service.impl.sys;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.sys.SysApprovalSetting;
import com.example.ymm.modules1.mapper.my.sys.SysApprovalSettingMapper;
import com.example.ymm.modules1.query.sys.SysApprovalSettingQueryCriteria;
import com.example.ymm.modules1.service.dto.heng.ApproverUserList;
import com.example.ymm.modules1.service.sys.SysApprovalSettingLineService;
import com.example.ymm.modules1.service.sys.SysApprovalSettingService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
//@DSTransactional
@DS("slave2")
@Slf4j
public class SysApprovalSettingServiceImpl extends BaseServiceImpl<SysApprovalSettingMapper, SysApprovalSetting> implements SysApprovalSettingService {


    @Autowired
    SysApprovalSettingLineService sysApprovalSettingLineService;

    @Override
    public TableList<SysApprovalSetting> list(SysApprovalSettingQueryCriteria criteria, YmPageDto pageDto) {
        IPage<SysApprovalSetting> page = new Page<SysApprovalSetting>(pageDto.getPage(),pageDto.getPageSize());
        QueryWrapper predicate = QueryHelpPlus.getPredicate(SysApprovalSetting.class, criteria);
        predicate.orderByDesc("create_time");
        baseMapper.selectPage(page, predicate);
        TableList<SysApprovalSetting> tableList=new TableList(page);
        return tableList;
    }

    public List<SysApprovalSetting> queryAll(SysApprovalSettingQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(SysApprovalSetting.class, criteria);
        predicate.orderByDesc("create_time");
        List<SysApprovalSetting> result =baseMapper.selectList(predicate);
        return result;
    }

    @Override
    public SysApprovalSetting findByApprovalName(String approvalName) {
        SysApprovalSettingQueryCriteria criteria = new SysApprovalSettingQueryCriteria();
        criteria.setApprovalName(approvalName);
        List<SysApprovalSetting> sysApprovalSettings = queryAll(criteria);
        if(sysApprovalSettings.size()>0){
            return sysApprovalSettings.get(0);
        }
        return null;
    }

    @Override
    public ApproverUserList getApproverUserList(String approvalSettingId,String userId) {
        return null;
    }
}
